<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="撰写需求" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入撰写需求"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        > -->
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" width="100" align="center" prop="id" />
      <el-table-column label="用户" align="center" prop="userName" />
      <el-table-column label="创建时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="撰写需求"
        align="center"
        prop="name"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="模板文件名" align="center" prop="docFileUrl">
        <template slot-scope="scope">
          {{
            (scope.row.docFileUrl && scope.row.docFileUrl.split("/")[1]) || ""
          }}
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="docStatus">
        <template slot-scope="scope">
          <el-tag :type="scope.row.docStatus == 2 ? 'success' : ''">{{
            scope.row.docStatus == 2 ? "完成" : "未完成"
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.rows"
      @pagination="getList"
    />

    <el-dialog title="详情" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="撰写需求" prop="name">
              <el-input v-model="form.name" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="模板文件名">
              <span>{{
                (form.docFileUrl && form.docFileUrl.split("/")[1]) || ""
              }}</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          :disabled="!Boolean(form.docFileUrl)"
          @click="onOpen"
          >下载模板文件</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { docPage, downloadDoc } from "@/api/fzz";

export default {
  name: "Job",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,

      // 是否显示弹出层
      open: false,
      dataList: [],
      queryParams: {
        page: 1,
        rows: 10,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询定时任务列表 */
    getList() {
      this.loading = true;
      docPage(this.queryParams).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    onOpen() {
      // console.log(this.form.docFileUrl);
      // downloadDoc(this.form.docFileUrl).then((res) => {
      //   console.log(res);
      // });
      window.open(
        `https://wxfzz.zhixinglegalaid.cn/aiapi/download_doc?filename=${this.form.docFileUrl}`
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.form = row;
      this.open = true;
    },
  },
};
</script>



<style lang="scss" scoped>
.file {
  color: #1890ff;
  cursor: pointer;
}
</style>